package com.lenovo.srl.dil.tiltbase.lib.model;

import android.content.Context;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.lenovo.srl.dil.tiltbase.lib.R;

public class ItemInfo {

	public View mView;
	public AppInfo mAppInfo;

	Context mContext;

	FrameLayout iconLayout;
	ImageView iconView;
	TextView titleTextView;

	public ItemInfo(Context context, View view, AppInfo appInfo) {
		this.mContext = context;
		this.mView = view;
		this.mAppInfo = appInfo;
		init();
	}

	private void init() {
		iconLayout = (FrameLayout) this.mView.findViewById(R.id.icon_layout);
		iconView = (ImageView) this.mView.findViewById(R.id.icon);
		titleTextView = (TextView) this.mView.findViewById(R.id.name);
		iconView.setImageDrawable(mAppInfo.getAppIcon());
		titleTextView.setText(mAppInfo.getAppLabel());
	}

	public void setSelected(boolean selected) {
		if (selected) {
			if (!isClicked) {
				iconLayout.setBackgroundResource(R.drawable.highlight);
			}
		} else {
			iconLayout.setBackgroundResource(0);
			isClicked = false;
		}
	}

	boolean isClicked = false;

	public void setClicked() {
		isClicked = true;
		iconLayout.setBackgroundResource(R.drawable.highlight_click);
		iconLayout.requestLayout();
		iconLayout.invalidate();
	}

	public boolean isSelected() {
		return mView.isSelected();
	}

	public int[] getIconLeftTop() {
		final int[] location = new int[2];
		iconView.getLocationOnScreen(location);
		return location;
	}

	// public int getIconTop() {
	// return iconLayout.getTop() + iconView.getTop();
	// }

	public int getIconWidth() {
		return iconView.getWidth();
	}

	public int getIconHeight() {
		return iconView.getHeight();
	}

	public void show() {
		if (mContext != null && mAppInfo != null) {
			mContext.startActivity(mAppInfo.getIntent());
		}
	}
}
